
const replaceLangeItem = function () {
// 翻译多语言
    let langType = "zh_CN";
    let cacheLangType = localStorage.getItem("langType");
    if (cacheLangType != null && cacheLangType !== "") {
        langType = cacheLangType;
    }
    const i18nTextEls = $("[i18n_text]");
    if (i18nTextEls.length > 0) {
        for (let i = 0; i < i18nTextEls.length; i++) {
            let key = $(i18nTextEls[i]).attr("i18n_text");
            let value = LANGUAGE_PACKAGE[langType][key];
            $(i18nTextEls[i]).text(value);
        }
    }

    const i18nAttrEls = $("[i18n_attr]");
    if (i18nAttrEls.length > 0) {
        for (let i = 0; i < i18nAttrEls.length; i++) {
            let i18nAttr = $(i18nAttrEls[i]).attr("i18n_attr");
            let i18nAttrArray = i18nAttr.split("|");
            let value = LANGUAGE_PACKAGE[langType][i18nAttrArray[1]];
            $(i18nAttrEls[i]).attr(i18nAttrArray[0], value);
        }
    }
}


const pullLanguagePackage = function () {
    // 加载多语言包
    let cacheLangPackageMd5 = localStorage.getItem("cacheLangPackageMd5");
    let isLoadMd5 = false;
    if (cacheLangPackageMd5 == null) {
        isLoadMd5 = true;
    } else {
        if (cacheLangPackageMd5 !== LANGUAGE_PACKAGE_MD5) {
            isLoadMd5 = true;
        }
    }
    if (isLoadMd5) {
        $.ajax({
            async: false,
            url: getUrl("language/package"),
            type:"GET",
            success: function (response, status, xhr) {
                LANGUAGE_PACKAGE = JSON.parse(response.data);
                localStorage.setItem("languagePackageString", response.data);
                localStorage.setItem("cacheLangPackageMd5", LANGUAGE_PACKAGE_MD5);
            }
        });
    } else {
        LANGUAGE_PACKAGE = JSON.parse(localStorage.getItem("languagePackageString"));
    }
}

pullLanguagePackage();
$(document).ready(function () {
    replaceLangeItem();
});